#include "AComb_Vector.h" 

	void AComb_Vector::Add_LTV(AComb_LTV input){
		Vcomb_LTV.push_back(input);
		num_LTV = num_LTV + 1;
		if(num_LTV>1){
			num_inter = num_LTV*(num_LTV-1)/2;
		}
	}

	void AComb_Vector::Set_Distance_Self(){
		_set_self = true;
		for(int i=0; i<num_LTV; i++){
			Vcomb_LTV[i].Set_Distance();
			ncomb_LTV.push_back(Vcomb_LTV[i].Num_Out());
			nangle_LTV += Vcomb_LTV[i].Num();
		}
	}

	void AComb_Vector::Set_Distance_Inter(){
		_set_inter = true;
		std::vector<int> arr;
		for (int i = 0; i<Vcomb_LTV.size(); i++){
			arr.push_back(i);
		}
		//ShowMessage(2,"Vcomb_LTV size", Vcomb_LTV.size(), arr);
		std::vector<std::vector<int> > ret = FMath::zFun(arr, 2);
		for(std::vector<int> &v:ret)
		{
		//	ShowMessage(2,"in Set_D_I", v[0], v[1]);
			AComb_Inter tmp(Vcomb_LTV[v[0]], Vcomb_LTV[v[1]]);
			//tmp.A().Print();
			//tmp.B().Print();
			tmp.Set_Distance();
			//tmp.Print();
			std::string name_tmp = Vcomb_LTV[v[0]].Title() + " & " + Vcomb_LTV[v[1]].Title();
		//	ShowMessage(2,"Vcomb_LTV name", name_tmp);

			Vinter.insert(std::pair<std::string, AComb_Inter> (name_tmp, tmp) );
			ninter.push_back(tmp.Num());
			nangle_inter += tmp.Num();
		}
	}

	void AComb_Vector::Set_Distance(){
		Set_Distance_Self();
		Set_Distance_Inter();
	}

	void AComb_Vector::Assign_Variables(CDraw &para, AVariable &var){
		ShowMessage(2,"in AComb_Vector::Assign_Variables,  var size before",var.var.size());
		for(int iter_LTV=0; iter_LTV<num_LTV; iter_LTV++){
			Vcomb_LTV[iter_LTV].Assign_Variables(para, var);
		}
	

		std::map<std::string, AComb_Inter> ::reverse_iterator it;
		for(it = Vinter.rbegin(); it != Vinter.rend(); it++){
			for(int iter_angle=0; iter_angle<  it-> second.angle.out1_out1_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.out1_out1_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.out1_out1_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.out1_out1_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.out1_out2_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.out1_out2_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.out1_out2_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.out1_out2_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.out1_comb_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.out1_comb_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.out1_comb_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.out1_comb_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.out1_left1_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.out1_left1_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.out1_left1_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.out1_left1_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.out1_left2_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.out1_left2_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.out1_left2_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.out1_left2_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}



			for(int iter_angle=0; iter_angle<  it-> second.angle.out2_out1_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.out2_out1_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.out2_out1_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.out2_out1_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.out2_out2_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.out2_out2_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.out2_out2_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.out2_out2_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.out2_comb_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.out2_comb_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.out2_comb_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.out2_comb_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.out2_left1_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.out2_left1_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.out2_left1_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.out2_left1_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.out2_left2_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.out2_left2_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.out2_left2_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.out2_left2_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}


			for(int iter_angle=0; iter_angle<  it-> second.angle.comb_out1_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.comb_out1_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.comb_out1_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.comb_out1_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.comb_out2_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.comb_out2_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.comb_out2_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.comb_out2_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.comb_comb_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.comb_comb_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.comb_comb_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.comb_comb_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.comb_left1_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.comb_left1_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.comb_left1_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.comb_left1_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.comb_left2_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.comb_left2_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.comb_left2_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.comb_left2_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}


			for(int iter_angle=0; iter_angle<  it-> second.angle.left1_out1_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.left1_out1_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.left1_out1_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.left1_out1_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.left1_out2_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.left1_out2_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.left1_out2_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.left1_out2_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.left1_comb_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.left1_comb_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.left1_comb_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.left1_comb_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.left1_left1_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.left1_left1_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.left1_left1_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.left1_left1_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.left1_left2_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.left1_left2_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.left1_left2_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.left1_left2_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}


			for(int iter_angle=0; iter_angle<  it-> second.angle.left2_out1_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.left2_out1_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.left2_out1_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.left2_out1_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.left2_out2_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.left2_out2_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.left2_out2_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.left2_out2_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.left2_comb_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.left2_comb_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.left2_comb_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.left2_comb_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.left2_left1_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.left2_left1_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.left2_left1_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.left2_left1_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
			for(int iter_angle=0; iter_angle<  it-> second.angle.left2_left2_angle.size(); iter_angle++){
				var_tmp.Set_Var( it-> second.angle.left2_left2_angle[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltar.left2_left2_DeltaR[iter_angle]);
				var.var.push_back(var_tmp);
				var_tmp.Set_Var( it-> second.deltaphi.left2_left2_DeltaPhi[iter_angle]);
				var.var.push_back(var_tmp);
			}
		}

		ShowMessage(2,"var size after",var.var.size());
	
	
	}

	void AComb_Vector::Print(std::string str){

		if(!_set_self){
			ShowMessage(2,"AComb_Vector: no input or not set distance yet");
			return;
		}

		ShowMessage("=");
		ShowMessage(2,"AComb_Vector: for", str);
		ShowMessage(3,"Number of Vcomb_LTV is", num_LTV);
		for(int i=0; i<num_LTV; i++){
			ShowMessage(4,"Name : ", Vcomb_LTV[i].Title(), " out vector number : ", Vcomb_LTV[i].Num_Out());
		}
		ShowMessage("-");
		for(int i=0; i<num_LTV; i++){
			ShowMessage(3,"Vcomb_LTV", std::to_string(i));
			Vcomb_LTV[i].Print(4);
		}
	
		if(!_set_inter){
			ShowMessage(2,"AComb_Vector: not set inter distance yet");
			return;
		}

		ShowMessage("-");
		std::map<std::string, AComb_Inter> ::reverse_iterator it;
		for(it = Vinter.rbegin(); it != Vinter.rend(); it++){
			ShowMessage(3,"Vinters are ", it->first);
		}
		ShowMessage("-");
		for(it = Vinter.rbegin(); it != Vinter.rend(); it++){
			ShowMessage(3,"Vinter ", it->first);
			it->second.Print(4);
		}
		ShowMessage("=");
	}
